package com.yy.tools.text
{
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	/**
	 * 文本处理类
	 * @author YY
	 */
	public class TextTool
	{
		public function TextTool()
		{
		}
		
		/**
		 * 处理文本
		 * @param tf
		 * @param w
		 * @param h
		 * @param autoSize
		 * @param wordWap
		 * @param textColor
		 * @param size
		 * @return 
		 * 
		 */
		public static function processTextField(tf:TextField, 
												textColor:uint=0xff0000,
												w:int=0,
												h:int=0,
												autoSize:String="left",
												wordWap:Boolean=false
		):TextField {
			if(w != 0) {
				tf.width = w;
			}
			if(h != 0) {
				tf.height = h;
			}
			tf.textColor = textColor;
			tf.autoSize = autoSize;
			tf.wordWrap = wordWap;
			return tf;
		}
		
		
		/**
		 *创建文本 
		 * @param defaultTxt
		 * @param textColor
		 * @param w
		 * @param h
		 * @param autoSize
		 * @param wordWap
		 * @param enable
		 * @return 
		 * 
		 */		
		public static function getTextField(
			defaultTxt:String = "",
			textColor:uint=0xff0000,
			w:int=0,
			h:int=0,
			autoSize:String="left",
			wordWap:Boolean=false,
			enable:Boolean = false
		):TextField {
			var tf:TextField = new TextField();
			tf.text = defaultTxt;
			tf.textColor = textColor;
			tf.autoSize = autoSize;
			tf.wordWrap = wordWap;
			tf.mouseEnabled = enable;
			if(w != 0) {
				tf.width = w;
			}
			if(h != 0) {
				tf.height = h;
			}
			return tf;
		}
		
		/**
		 * 获得字体格式
		 * @param size  大小
		 * @param font  字体
		 * @return 
		 * 
		 */
		public static function getTextFormat(size:int, font:String=null,align:String="left"):TextFormat {
			var tf:TextFormat = new TextFormat();
			tf.size = size;
			tf.font = font;
			tf.align = TextFormatAlign.CENTER;
			return tf;
		}
	}
}